package team.lourd.network.system.config;

import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.context.SecurityContextHolder;

/** 
* @Description: Spring Jpa Auditor配置
* @Author: Lourd 
* @Date: 2019/1/17
*/
@Configuration
public class AuditorAwareConfig {


    /**
    * @Description:
    * 在异步方法中如何获取用户信息
    * SecurityContextHolder的主要功能是将当前执行的进程和SecurityContext关联起来。
    * SecurityContextHolder.MODE_INHERITABLETHREADLOCAL ：用于线程有父子关系的情景中，子线程集成父线程的SecurityContextHolder；
    * SecurityContextHolder.MODE_INHERITABLETHREADLOCAL ：全局共用SecurityContextHolder
    * @Param: []
    * @return: org.springframework.beans.factory.config.MethodInvokingFactoryBean
    * @Author: Lourd
    * @Date: 2019/1/17
    */
    @Bean
    public MethodInvokingFactoryBean methodInvokingFactoryBean() {
        MethodInvokingFactoryBean methodInvokingFactoryBean = new MethodInvokingFactoryBean();
        methodInvokingFactoryBean.setTargetClass(SecurityContextHolder.class);
        methodInvokingFactoryBean.setTargetMethod("setStrategyName");
        methodInvokingFactoryBean.setArguments(new String[]{SecurityContextHolder.MODE_INHERITABLETHREADLOCAL});
        return methodInvokingFactoryBean;
    }
}